<script src="<?php echo $base_url?>js/jquery-1.4.4.js" type="text/javascript"></script>
<script type="text/javascript">
function funViewCla(classified) {
	window.location='index.php?classified='+classified;
}
function funDelCla(postId) {
	var delPro=confirm("Are you sure want to delete this classified?");
	if(delPro==true) {
		var frm = document.getElementById('form1');
		document.getElementById("delCla").value=postId;
		frm.submit();
	}	
}

</script>
<?php
require_once "../includes/pagination.php";

if(!empty($_POST['delCla']))
{
	$claId=$_POST['delCla'];
	$sqlDelMem="Delete from tbl_post where post_id=$claId";
	$rstDelMem=mysql_query($sqlDelMem);	
}


$cond = '';
$sort = '';
$ut = $u = $fn = $ln = $dg = 'asc';
if(isset($_GET['sort']))
{
	
	if($_GET['sort']=='user_type')
	{
		if($_GET['s_type']=='asc')
		{	$cond=' ORDER BY user_type ASC';	$sort = '&sort=user_type&s_type=asc';	$ut='desc';	}
		else
		{	$cond=' ORDER BY user_type DESC';	$sort = '&sort=user_type&s_type=desc';	}
	}
	else if($_GET['sort']=='buyers')
	{
		if($_GET['s_type']=='asc')
		{	$cond=' AND user_type=1 ORDER BY username ASC';	$sort = '&sort=buyers&s_type=asc';	$ut='desc';	}
		else
		{	$cond=' AND user_type=1 ORDER BY username DESC';	$sort = '&sort=buyers&s_type=desc';	}
	}
	else if($_GET['sort']=='sellers')
	{
		if($_GET['s_type']=='asc')
		{	$cond=' AND user_type=2 ORDER BY username ASC';	$sort = '&sort=sellers&s_type=asc';	$ut='desc';	}
		else
		{	$cond=' AND user_type=2 ORDER BY username DESC';	$sort = '&sort=sellers&s_type=desc';	}
	}
	else if($_GET['sort']=='merchants')
	{
		if($_GET['s_type']=='asc')
		{	$cond=' AND user_type=3 ORDER BY username ASC';	$sort = '&sort=merchants&s_type=asc';	$ut='desc';	}
		else
		{	$cond=' AND user_type=3 ORDER BY username DESC';	$sort = '&sort=merchants&s_type=desc';	}
	}
	else if($_GET['sort']=='wholesalers')
	{
		if($_GET['s_type']=='asc')
		{	$cond=' AND user_type=5 ORDER BY username ASC';	$sort = '&sort=wholesalers&s_type=asc';	$ut='desc';	}
		else
		{	$cond=' AND user_type=5 ORDER BY username DESC';	$sort = '&sort=wholesalers&s_type=desc';	}
	}
	else if($_GET['sort']=='username')
	{
		if($_GET['s_type']=='asc')
		{	$cond=' ORDER BY username ASC';		$sort = '&sort=username&s_type=asc';	$u='desc';	}
		else
		{	$cond=' ORDER BY username DESC';	$sort = '&sort=username&s_type=desc';	}
	}
	else if($_GET['sort']=='first_name')
	{
		if($_GET['s_type']=='asc')
		{	$cond=' ORDER BY first_name ASC';	$sort = '&sort=first_name&s_type=asc';	$fn='desc';	}
		else
		{	$cond=' ORDER BY first_name DESC';	$sort = '&sort=first_name&s_type=desc';	}
	}
	else if($_GET['sort']=='last_name')
	{
		if($_GET['s_type']=='asc')
		{	$cond=' ORDER BY last_name ASC';	$sort = '&sort=last_name&s_type=asc';	$ln='desc';	}
		else
		{	$cond=' ORDER BY last_name DESC';	$sort = '&sort=last_name&s_type=desc';	}
	}
	else if($_GET['sort']=='created_date')
	{
		if($_GET['s_type']=='asc')
		{	$cond=' ORDER BY created_date ASC';	$sort = '&sort=created_date&s_type=asc'; $dg='desc'; }
		else
		{	$cond=' ORDER BY created_date DESC';	$sort = '&sort=created_date&s_type=desc';}
	}
}

?>
<form name="form1" id="form1" method="post" action="">
 <input type="hidden" name="delCla" id="delCla">
			  
<table width="100%"  border="1" cellspacing="0" class="container">
  <tr>
    <td width="469" height="25" class="tdHeader">Classified List(Incomplete)</td>
  </tr>
  <tr>
    <td height="577">
	<table width="100%">
            <tbody>
		<tr>
			<td>
			<form name="frmSearchPro" action="" method="post">
				<table width="100%" border="0">
					<tr><td height="10"></td><td></td><td></td><td></td><td></td></tr>
					<tr>
						<td width="2%" height="31"></td>
						<td width="16%">Clasified Name</td>
						<td width="30%"><input type="text" name="productName" id="productName" style="width:157px;"  /></td>
						<td width="13%">Posted by</td>
						<td width="39%"><input type="text" name="postedBy" id="postedBy" style="width:215px;" /></td>
					</tr>
					<tr>
						<td height="34">&nbsp;</td>
						<td>Price range</td>
						<td>
							<input type="text" name="priceFrom" id="priceFrom" style="width:67px;" onkeydown='return onlyint(event);' /> &nbsp;&nbsp;
							<input type="text" name="priceTo" id="priceTo" style="width:67px;" onkeydown='return onlyint(event);' />
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<font color="gray">From</font>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<font color="gray">To</font><br />
							<div style="text-align: center; color: red; display: none;" id="digit_err">Digits  Only</div>
							<?php /*
							<select name="priceFrom" id="priceFrom" style="width:78px;">
								<option value="">From</option>
								<?php
								$i=0;
								for($i=0; $i<=5000; $i+=100) {
								echo "<option value='$i'> $$i </option>";
								}
								?>
							</select>
							    
							
							
							<select name="priceTo" id="priceTo"  style="width:78px;">
								<option value="">To</option>
								<?php
								$i=100;
								for($i=100; $i<=5000; $i+=100) {
								echo "<option value='$i'> $$i </option>";
								}
								?>
							</select>  */
							?>
						</td>
						<td>Posted date</td>
						<td>
							<select name="dMonth" id="dMonth" style="width:80px">
								<option value="">..Month..</option>
								<option value="01">January</option>
								<option value="02">February</option>
								<option value="03">March</option>
								<option value="04">April</option>
								<option value="05">May</option>
								<option value="06">June</option>
								<option value="07">July</option>
								<option value="08">August</option>
								<option value="09">September</option>
								<option value="10">October</option>
								<option value="11">November</option>
								<option value="12">December</option>
							</select>
							<select name="dDay" id="dDay" style="width:80px">
								<option value="">..Day..</option>
								<?php
								for($i=1;$i<=31;$i++) {
									if($i<=9)
									$date = '0'.$i;
									else
									$date = $i;
									?>
									<option value="<?php echo $date;?>"><?php echo $date;?></option>
									<?php
								}
								?>
								
							</select>
							<input type="dYear" name="dYear" id="emailAgain3" value="YYYY" onclick="this.value=''" size="4" maxlength="4" />
						</td>
					</tr>
					<tr>
						<td height="35" colspan="5" style="text-align:center"><input type="submit" name="btnSearchPro" value="Search Product" /></td>
					</tr>
				</table>
			</form>
			</td>
		</tr>
		<tr>
			<td>
				<b>Sort  By :</b> 	<a href="<?php echo $base_url;?>admin/index.php?members&sort=user_type&s_type=<?php echo $ut;?>">All</a> &nbsp;&nbsp;&nbsp;
                        <a href="<?php echo $base_url;?>admin/index.php?members&sort=buyers&s_type=<?php echo $ut;?>">Buyers</a> &nbsp;&nbsp;&nbsp;
                        <a href="<?php echo $base_url;?>admin/index.php?members&sort=sellers&s_type=<?php echo $ut;?>">Sellers</a> &nbsp;&nbsp;&nbsp;
					    <a href="<?php echo $base_url;?>admin/index.php?members&sort=merchants&s_type=<?php echo $ut;?>">Merchants</a> &nbsp;&nbsp;&nbsp;	
                        <a href="<?php echo $base_url;?>admin/index.php?members&sort=wholesalers&s_type=<?php echo $ut;?>">Wholesalers</a> &nbsp;&nbsp;&nbsp;	
						<a href="<?php echo $base_url;?>admin/index.php?members&sort=username&s_type=<?php echo $u;?>">Username</a> &nbsp;&nbsp;&nbsp;
						<a href="<?php echo $base_url;?>admin/index.php?members&sort=first_name&s_type=<?php echo $fn;?>">First name</a> &nbsp;&nbsp;&nbsp;
						<a href="<?php echo $base_url;?>admin/index.php?members&sort=last_name&s_type=<?php echo $ln;?>">Last name</a> &nbsp;&nbsp;&nbsp;
						<a href="<?php echo $base_url;?>admin/index.php?members&sort=created_date&s_type=<?php echo $dg;?>">Date Regd.</a>
			</td>
		</tr>
        </tbody></table>
	<br>
	<table width="100%"  border="0" cellspacing="0">      
      <tr class="InnerHeader">       
        <td width="16%" class="line">Name</td>
		<td width="14%" class="line">Location </td>
        <td width="13%" class="line">Price</td>
        <td width="17%" class="line">Post Date</td>
        <td width="7%" class="line">&nbsp;</td> 
		<td width="10%" class="line">&nbsp;</td>         
      </tr>
      <?php 				 
	
	$itemPerPage=15;
	$search='';
	if(isset($_POST['btnSearchPro'])) {
		
		$username 	= $_POST['username'];		
		$user_type 	= $_POST['user_type'];
		$first_name 	= $_POST['first_name'];
		$last_name 	= $_POST['last_name'];
		
		if($username!='')
		$search.= " AND username='".$username."'";
		
		if($user_type!='')
		$search.=" AND user_type='".$user_type."'";
		
		if($first_name!='')
		$search.="AND first_name='".$first_name."'";
		
		if($last_name!='')
		$search.="AND last_name='".$last_name."'";
		
	}
	//$sql_shocat="SELECT * FROM tbl_users where status!=0 AND status!=2 $search $cond";	
	$sql_shocat="SELECT * FROM tbl_post";	
	//echo $sql_shocat;
	$rst_shocat=mysql_query(getPagingQuery($sql_shocat,$itemPerPage));
	$numRows = mysql_num_rows($rst_shocat);
	if($numRows>0) {				
		while($row_shocat = mysql_fetch_array($rst_shocat)) {				 
		$post_id=$row_shocat['post_id'];
		$name=stripslashes($row_shocat['post_name']);
		$location=stripslashes($row_shocat['post_location']);
		$price=stripslashes($row_shocat['price']);
		$post_date=$row_shocat['posted_date'];

		echo "<tr>";
		echo "<td class='line'>$name</td>";
		echo "<td class='line'>$location</td>";
		echo "<td class='line'>$price</td>";
		echo "<td class='line'>$post_date</td>";
		echo "<td height='20' class='line'><input type='button' name='view' value='View' class='button'  onclick='funViewCla($post_id)'></td> ";
		echo "<td height='20' class='line'><input type='button' name='delete' value='Delete' class='button'  onclick='funDelCla($post_id)';></td> ";
		echo "</tr>";				
		}
	} else {
	       echo "<tr>
			       <td colspan='6' class='line'>No Classified found.</td>
			 </tr>";
	}				 
		?>      
       </table>
	<div align="center">
		<?php		   
		   $link="classified";
		   echo $disp=getPagingLink($sql_shocat,$itemPerPage,$link,$sort);							   
		?>    
	</div>
	</td>
 </tr>
</table>